#!/bin/bash
#获取时间戳
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`

#获取集群信息
clusterid=$(cat /etc/kubernetes/config | grep KUBE_CLUSTER | awk -F '[=]' '{print $2}' | sed 's/\"//g')

#获取ip信息
DEVICE=`/usr/sbin/route -n|grep -w UG|awk '{print $NF}'|sort |uniq`
MYIP=`/usr/sbin/ifconfig $DEVICE|grep 'inet '|awk '{print $2}'|egrep -o '[0-9]{1,3}(\.[0-9]{1,3}){3}'`


#基本信息
app=devcloud
set=tkestack
mod=node
name=${clusterid}_${MYIP}
access_host="zhiyan.monitor.access.inner.oa.com"


#########################################################检查nfs挂载######################################################
app_mark=1084_8875_DevCloudNfsFault
count=`ps -C mount.nfs -o pid,ppid,start_time,state,wchan,comm,args|wc -l`
#上报的数据
report_data="[{\\\"metric\\\":\\\"count\\\",\\\"value\\\":${count},\\\"tags\\\":{\\\"name\\\":\\\"${name}\\\",\\\"app\\\":\\\"${app}\\\",\\\"set\\\":\\\"${set}\\\",\\\"mod\\\":\\\"${mod}\\\"}}]"
#进行上报
curl -v -H "Content-Type: application/json" -X POST -d "{\"cur_agent_time\":"${timeStamp}", \"old_agent_time\":"${timeStamp}", \"old_collector_time\":"${timeStamp}", \"pkg_seq\":"${timeStamp}", \"report_cnt\":1, \"app_mark\":\"${app_mark}\" ,\"report_data\":\"$report_data\", \"instance_mark\":\"${MYIP}\", \"report_ip\":\"ip\",\"data_type\":0, \"method\":1}" http://"${access_host}":8080/access_v1.http_service/HttpCurveReportRpc  


#########################################################检查僵尸进程#######################################################
app_mark=1084_9572_DevCloud_defunct_count
count=`ps -ef | grep defunct | grep -v grep | wc -l`
#上报的数据
report_data="[{\\\"metric\\\":\\\"count\\\",\\\"value\\\":${count},\\\"tags\\\":{\\\"name\\\":\\\"${name}\\\",\\\"app\\\":\\\"${app}\\\",\\\"set\\\":\\\"${set}\\\",\\\"mod\\\":\\\"${mod}\\\"}}]"
#进行上报
curl -v -H "Content-Type: application/json" -X POST -d "{\"cur_agent_time\":"${timeStamp}", \"old_agent_time\":"${timeStamp}", \"old_collector_time\":"${timeStamp}", \"pkg_seq\":"${timeStamp}", \"report_cnt\":1, \"app_mark\":\"${app_mark}\" ,\"report_data\":\"$report_data\", \"instance_mark\":\"${MYIP}\", \"report_ip\":\"ip\",\"data_type\":0, \"method\":1}" http://"${access_host}":8080/access_v1.http_service/HttpCurveReportRpc  


#########################################################devcloud_本地盘_inode号利用率#######################################################
app_mark=1084_11490_devcloud_local_disk_inode_used
count=`df -li|grep /dockerData|awk '{print $5}'|awk -F% '{print $1}'|sort -n|tail -1`
#上报的数据
report_data="[{\\\"metric\\\":\\\"count\\\",\\\"value\\\":${count},\\\"tags\\\":{\\\"name\\\":\\\"${name}\\\",\\\"app\\\":\\\"${app}\\\",\\\"set\\\":\\\"${set}\\\",\\\"mod\\\":\\\"${mod}\\\"}}]"
#进行上报
curl -v -H "Content-Type: application/json" -X POST -d "{\"cur_agent_time\":"${timeStamp}", \"old_agent_time\":"${timeStamp}", \"old_collector_time\":"${timeStamp}", \"pkg_seq\":"${timeStamp}", \"report_cnt\":1, \"app_mark\":\"${app_mark}\" ,\"report_data\":\"$report_data\", \"instance_mark\":\"${MYIP}\", \"report_ip\":\"ip\",\"data_type\":0, \"method\":1}" http://"${access_host}":8080/access_v1.http_service/HttpCurveReportRpc  
